"""
pip install tf2onnx

python -m tf2onnx.convert --saved-model model2 --output model.onnx --opset 11 --tag serve
"""

import numpy as np
import onnx
import onnxruntime
from keras.preprocessing.image import load_img, img_to_array
from keras.applications.efficientnet_v2 import preprocess_input

img_size = (64, 64)


if __name__ == '__main__':
	# onnx_model = onnx.load("./model.onnx")
	# check = onnx.checker.check_model(onnx_model)
	# print('Check: ', check)  # 输出为 Check: None 则表示无报错信息，模型导出正确。
	
	img = load_img('/Users/summy/Downloads/dataset-resized/glass/glass1.jpg', target_size=img_size)
	print(img.size)
	x = img_to_array(img)
	x = np.expand_dims(x, axis=0)
	x = preprocess_input(x)
	
	ort_sess = onnxruntime.InferenceSession("./model.onnx", providers=['CPUExecutionProvider'])
	ort_inputs = {ort_sess.get_inputs()[0].name: x}
	ort_outs = ort_sess.run(None, ort_inputs)

	print(ort_outs)
